package floappcontest.core.backbeans;

import floappcontest.core.beans.Contest;
import floappcontest.core.control.Control;
import floappcontest.core.dao.factory.HibernateDAOFactory;
import floappcontest.core.exception.FloAppException;

/**
 * 
 *  
 */
public class Floapp {
	
	private static final String FAILED = "FAILED"; //$NON-NLS-1$

	private static final String OK = "OK"; //$NON-NLS-1$

	private Control control;

	private Contest contest;
	
	public Floapp() {
		setControl( new Control( new HibernateDAOFactory() ) );
		setContest( new Contest() );
	}

	/**
	 * @return
	 */
	public Contest getContest(){
		return this.contest;
	}
	
	/**
	 * @param contest
	 */
	public void setContest(Contest contest) {
		this.contest = contest;
	}
	
	/**
	 * @return
	 */
	public String insertContest() {
		try {
			getControl().insertContest( getContest() );
			setContest( new Contest() );
			return OK;
		} catch (FloAppException e) {
			setContest( new Contest() );
			return FAILED;
		} 
	}	

	/**
	 * @return
	 */
	public Control getControl() {
		return this.control;
	}

	/**
	 * @param control
	 */
	public void setControl(Control control) {
		this.control = control;
	}
}
